<template>
  <el-dialog title="请选择发布客户端" :visible.sync="pushNews.dialogVisible" size="tiny">
        <div v-loading="loading">
            <el-form>
                <div class="text-ag">
                    <el-checkbox v-model="checked1">家庭端</el-checkbox>
                    <el-checkbox v-model="checked2">教学端</el-checkbox>
                </div>
            </el-form>
            <span slot="footer" class="dialog-footer">
                <el-row type="flex" class="row-bg" justify="center">
                    <el-col :span="4" class="mr"><el-button @click="pushNews.dialogVisible = false">取 消</el-button></el-col>
                    <el-col :span="4"><el-button type="primary" @click="confirm" :disabled="!checked1 && !checked2">发 布</el-button></el-col>
                </el-row>
            </span>
        </div>
    </el-dialog>       
</template>
<script>
import { uploadHeadLine } from "api/newTope";
export default {
  name: "pushNews",
  data() {
    return {
      dialogVisible: false,
      loading: false,
      checked1: true,
      checked2: true
    };
  },
  props: {
    pushNews: {
      type: Object,
      required: true
    }
  },
  methods: {
    confirm() {
      this.loading = true;
      uploadHeadLine(this.pushNews.pId,this.add())
        .then(data => {
          this.loading = false;
          this.$message({
            message: "发布成功!",
            type: "success"
          });
          this.pushNews.dialogVisible = false;
          this.$emit("setSon", "删除成功");
        })
        .catch(error => {
          this.laoding = false;
        });
    },
    add() {
      if (this.checked1 && this.checked2) {
        return "2";
      } else if (this.checked1) {
        return "0";
      } else{
        return "1";
      }
    }
  }
};
</script>
<style lang="scss" scoped>
.text-ag {
  text-align: center;
  margin-bottom: 20px;
}
.mr {
  margin-right: 30px !important;
}
</style>

